home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2614.ZIP / DISPLA.ZIP / DISPSUB.ASM < prev    next >
Assembly Source File  |  1990-12-22  |  9KB  |  316 lines

  1.         PAGE    66, 80
  2.         TITLE   Subroutines for the dispfile() routine
  3.  
  4. .MODEL LARGE
  5.  
  6. ;
  7. ; filename - dispsub.asm
  8. ;
  9. ; compile  - masm /mx dispsub;
  10. ;
  11. ; written by:  Mike Taylor
  12. ;              September 10th, 1988
  13. ;
  14. ; updated:     December 23, 1990
  15. ;
  16.  
  17. .CODE
  18.  
  19.  
  20. ;  Function:    unsigned d_vconfig(void);
  21. ;  Parameters:  none
  22. ;
  23. ;               call with C style parameter passing
  24. ;
  25. ;  Purpose:     to return the segment address of the active video device
  26. ;
  27.  
  28.         PUBLIC  _d_vconfig
  29. _d_vconfig PROC
  30.  
  31.         xor     ax,ax           ; clear ax
  32.         mov     ah,0fh          ; bios function 0fh, get video mode
  33.         int     10h
  34.  
  35.         cmp     al,7            ; did bios return mono (= 7)?
  36.         jnz     v1              ; if no, then color
  37.         mov     ax,0b000h       ; yes, switch to mono segment
  38.         jmp     v2              ; bypass color assignment
  39. v1:
  40.         mov     ax,0b800h       ; color segment
  41. v2:
  42.         ret                     ; return segment in ax to caller
  43. _d_vconfig ENDP
  44.  
  45.  
  46. ;
  47. ;  Function:    void d_gotoxy(int, int)
  48. ;  Parameters:  int - x coordinate for the new cursor position
  49. ;               int - y coordinate for the new cursor position
  50. ;
  51. ;               0 > x > 79   and   0 > y > 24
  52. ;
  53. ;               call with C style parameter passing
  54. ;
  55. ;  Purpose:     to place the cursor at the x,y coordinates
  56. ;
  57.  
  58.         PUBLIC  _d_gotoxy
  59. _d_gotoxy PROC
  60.  
  61.         push    bp              ; save the caller's bp register
  62.         mov     bp,sp           ; establish our base pointer into the stack
  63.         push    bx              ; save bx and dx registers
  64.         push    dx
  65.  
  66.         xor     ax,ax           ; clear ax register
  67.         xor     bx,bx           ; bx = 0 means video page 0
  68.         mov     dh, [bp + 8]    ; get y coordinate
  69.         mov     dl, [bp + 6]    ; get x coordinate
  70.         mov     ah,2            ; bios function 02h, set cursor position
  71.         int     10h
  72.  
  73.         xor     ax,ax           ; clear ax register
  74.  
  75.         pop     dx              ; restore caller's registers
  76.         pop     bx
  77.         pop     bp
  78.         ret
  79. _d_gotoxy ENDP
  80.  
  81.  
  82.  
  83. ;
  84. ;  Function:    int d_fileopen(char *, int mode)
  85. ;  Parameters:  char * - filename
  86. ;               access - file access mode       0 = read only
  87. ;                                               1 = write only
  88. ;                                               2 = read/write
  89. ;
  90. ;               call with C style parameter passing
  91. ;
  92. ;  Purpose:     to open a DOS file and return it's handle.
  93. ;
  94.  
  95.         PUBLIC  _d_fileopen
  96. _d_fileopen PROC
  97.  
  98.         push    bp              ; save the caller's bp register
  99.         mov     bp,sp           ; establish our base pointer into the stack
  100.  
  101.         push    bx              ; save caller's registers
  102.         push    dx
  103.         push    ds
  104.  
  105.         mov     dx,[bp + 6]     ; offset of filename
  106.         mov     ax,[bp + 8]     ; segment of filename
  107.         push    ax              ; make filename segment into default segment
  108.         pop     ds
  109.         mov     ax,[bp + 10]    ; access mode for file, stored in ah
  110.  
  111.         mov     ah,3dh          ; dos function 3dh, file open
  112.         int     21h
  113.  
  114.         jnc     _fo1            ; if carry flag set then error occured
  115.         xor     ax,ax
  116.  
  117. _fo1:
  118.         pop     ds              ; restore caller's registers
  119.         pop     dx
  120.         pop     bx
  121.         pop     bp
  122.  
  123.         ret
  124.  
  125. _d_fileopen ENDP
  126.  
  127.  
  128. ;
  129. ;  Function:    int d_fileread(int, char *, int)
  130. ;  Parameters:  int    - dos file handle
  131. ;               char * - char pointer to read buffer (pass as a FAR pointer)
  132. ;               int    - # of characters to read in
  133. ;
  134. ;               call with C style parameter passing
  135. ;
  136. ;  Purpose:     to read in from a file the specified number of bytes
  137. ;               into the buffer address passed.  Returns the # of bytes
  138. ;               actually read in.
  139. ;
  140.  
  141.         PUBLIC  _d_fileread
  142. _d_fileread PROC
  143.  
  144.         push    bp              ; save the caller's bp register
  145.         mov     bp,sp           ; establish our base pointer into the stack
  146.  
  147.         push    bx              ; save caller's registers
  148.         push    cx
  149.         push    dx
  150.         push    ds
  151.  
  152.         mov     bx,[bp + 6]     ; file handle
  153.         mov     dx,[bp + 8]     ; offset of buffer
  154.         mov     ax,[bp + 10]    ; segment of buffer
  155.         push    ax              ; make buffer segment into default data segment
  156.         pop     ds
  157.         mov     cx,[bp + 12]    ; byte count to read in
  158.         xor     ax,ax           ; clear ax register
  159.         mov     ah,3fh          ; dos function 3fh, file block read
  160.         int     21h
  161.  
  162.         jnc     _fr1            ; if carry flag set then error occured
  163.         xor     ax,ax           ;   and notify by returning 0 bytes
  164.                                 ; otherwise ax will contain the actual
  165.                                 ; bytes read in.
  166.  
  167. _fr1:
  168.         pop     ds              ; restore caller's registers
  169.         pop     dx
  170.         pop     cx
  171.         pop     bx
  172.         pop     bp
  173.  
  174.         ret
  175.  
  176. _d_fileread ENDP
  177.  
  178.  
  179. ;
  180. ;  Function:    long d_fileseek(int, long, int)
  181. ;  Parameters:  int  - dos file handle
  182. ;               long - new offset to position file pointer
  183. ;               int  - direction of offset
  184. ;
  185. ;               direction 0 = seek from start of file
  186. ;                         1 = seek from current position
  187. ;                         2 = seek from end of file
  188. ;
  189. ;               call with C style parameter passing
  190. ;
  191. ;  Purpose:     to place the file pointer at the specified offset
  192. ;               and return the new offset as a long variable in dx, ax
  193. ;
  194.  
  195.         PUBLIC  _d_fileseek
  196. _d_fileseek PROC
  197.  
  198.         push    bp              ; save the caller's bp register
  199.         mov     bp,sp           ; establish our base pointer into the stack
  200.         push    bx              ; save bx and cx registers
  201.         push    cx
  202.  
  203.         mov     bx,[bp + 6]     ; file handle
  204.         mov     cx,[bp + 10]    ; msb of long offset parameter
  205.         mov     dx,[bp + 8]     ; lsb of long offset parameter
  206.         mov     al,[bp + 12]    ; seek direction code
  207.         mov     ah,42h          ; dos function 42h, set file pointer
  208.         int     21h
  209.  
  210.         jnc     _f1             ; if carry flag not set, no error
  211.         xor     ax,ax           ; if error, clear pointer msb and lsb
  212.         xor     dx,dx
  213. _f1:
  214.         pop     cx              ; restore caller's registers
  215.         pop     bx
  216.         pop     bp
  217.         ret
  218. _d_fileseek ENDP
  219.  
  220. ;
  221. ;  Function:    long d_filepos(int)
  222. ;  Parameters:  int    - dos file handle
  223. ;
  224. ;               call with C style parameter passing
  225. ;
  226. ;  Purpose:     to return the current file pointer value.  This is done
  227. ;               by calling the set file pointer function with an offset
  228. ;               of 0 from the current position.  The new position (the
  229. ;               same since the offset was 0,) will be returned as a long
  230. ;               variable in the ax and dx registers.
  231. ;
  232.  
  233.         PUBLIC  _d_filepos
  234. _d_filepos PROC
  235.  
  236.         push    bp              ; save the caller's bp register
  237.         mov     bp,sp           ; establish our base pointer into the stack
  238.         push    bx              ; save caller's registers
  239.         push    cx
  240.  
  241.         mov     ah,42h          ; dos function 42h, set file pointer
  242.         mov     al,1            ; seek from current position
  243.         xor     cx,cx           ; for 0 bytes (long value in cx and dx)
  244.         xor     dx,dx
  245.         mov     bx,[bp + 6]     ; file handle
  246.         int     21h
  247.  
  248.         jnc     _fp1
  249.         xor     ax,ax
  250.         xor     dx,dx
  251.  
  252. _fp1:
  253.         pop     cx              ; restore caller's registers
  254.         pop     bx
  255.         pop     bp
  256.         ret
  257. _d_filepos ENDP
  258.  
  259. ;
  260. ;  Function:    int d_fileclose(int)
  261. ;  Parameters:  int - valid file handle
  262. ;
  263. ;               call with C style parameter passing
  264. ;
  265. ;  Purpose:     to close a DOS file handle.
  266. ;
  267.  
  268.         PUBLIC  _d_fileclose
  269. _d_fileclose PROC
  270.  
  271.         push    bp              ; save the caller's bp register
  272.         mov     bp,sp           ; establish our base pointer into the stack
  273.  
  274.         push    bx              ; save caller's registers
  275.  
  276.         mov     bx,[bp + 6]     ; file handle
  277.         xor     ax,ax
  278.         mov     ah,3eh          ; dos function 3eh, file close
  279.         int     21h
  280.  
  281.         jc      _fc1            ; if carry flag set then error occured
  282.                                 ;  ax will contain error number
  283.         xor     ax,ax           ; else return 0
  284. _fc1:
  285.         pop     bx              ; restore caller's registers
  286.         pop     bp
  287.  
  288.         ret
  289.  
  290. _d_fileclose ENDP
  291.  
  292. ;
  293. ;  Function:    char d_getkey(void)
  294. ;  Parameters:  none
  295. ;
  296. ;               call with C style parameter passing
  297. ;
  298. ;  Purpose:     to return the current key pressed
  299. ;
  300.  
  301.         PUBLIC  _d_getkey
  302. _d_getkey PROC
  303.  
  304.         xor     ax,ax           ; clear ax register
  305.         mov     ah,07h          ; dos function 07h, get key pressed
  306.         int     21h
  307.  
  308.         mov     ah,0            ; zero out msb of ax to make sure returned
  309.  
  310.         ret                     ;   value is only a byte value
  311.  
  312. _d_getkey ENDP
  313.  
  314.  
  315.         END
  316.